package com.luo.contentprovider.ui;

import com.luo.contentprovider.domain.db.PersonDaoImpl;

import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
import android.net.Uri;
import android.util.Log;

/**
 * 
 * @author lenovo
 *
 */
public class MyProvider extends ContentProvider
{
	private static final String TAG = MyProvider.class.getSimpleName();
	
	
	/**
	 * 
	 *  @ {@link Builder#scheme(String)}使用的字符串格式不带冒号！！！
	 *  
	 */
	public static final String SECHEM_NAME = "content" ;
	
	public static final String SECHEM_STR = "content://" ;
	
	public static final String AUTHORITY = "com.luo.content" ;
	
	public static final String PATH_PERSON = "person" ;


	
	
	@Override
	public boolean onCreate()
	{
		Log.i(TAG, " -----onCreate");
		
		return false;
	}

	@Override
	public Cursor query(Uri uri, String[] projection, String selection,
			String[] selectionArgs, String sortOrder)
	{
		return null;
	}

	@Override
	public String getType(Uri uri)
	{
//		方法用于返回当前Url所代表数据的MIME类型。
		return null;
	}

	@Override
	public Uri insert(Uri uri, ContentValues values)
	{
		//常量UriMatcher.NO_MATCH表示不匹配任何路径的返回码
		UriMatcher  sMatcher = new UriMatcher(UriMatcher.NO_MATCH);
		final int code = 1;//返回码
		
		sMatcher.addURI(AUTHORITY, PATH_PERSON, code);
		
		switch (sMatcher.match(uri))
		{
			case code:

				PersonDaoImpl.getInstance(getContext()).insertPerson(values);
				Log.i(TAG, "--match 111--");
				break;

			default:
				break;
		}
		
		
		//监听
		 getContext().getContentResolver().notifyChange(uri, null);
		return null;
	}

	@Override
	public int delete(Uri uri, String selection, String[] selectionArgs)
	{
		return 0;
	}

	@Override
	public int update(Uri uri, ContentValues values, String selection,
			String[] selectionArgs)
	{
		return 0;
	}

}
